<?php
$connect = mysql_connect('localhost','root','');
mysql_select_db("admintool");
error_reporting(E_ALL ^ E_NOTICE);
session_start();
?>
<?php
if($_SESSION["loggedin"]==true && $_SESSION["role"]==admin)
{
if(isset($_SESSION[msg]))
{
echo $_SESSION[msg];
unset($_SESSION[msg]);
}
?>
<?php 
$selectrole = "SELECT * from role_management";
$roles = mysql_query($selectrole);
//$rolemg = mysql_fetch_array($roles);
//print_r($rolemg);

?>
<form action="add.php" method="post">
<label>Employee Name</label>
<input type="text" value="<?php echo $_POST['addempname'];?>" name="addempname" /><br><br>
<label>Father Name</label>
<input type="text" value="<?php echo $_POST['addfathername'];?>" name="addfathername" /><br><br>
<label>Mother Name</label>
<input type="text" value="<?php echo $_POST['addmothername'];?>" name="addmothername" /><br><br>
<label>Address</label>
<textarea value="<?php echo $_POST['addaddress'];?>" name="addaddress" ></textarea><br><br>
<label>PAN card No</label>
<input type="text" value="<?php echo $_POST['addpanno'];?>" name="addpanno" /><br><br>
<label>Email id</label>
<input type="text" value="<?php echo $_POST['addemailid'];?>" name="addemailid" /><br><br>
<label>Mobile/Telephone</label>
<input type="text" value="<?php echo $_POST['addmobile'];?>" name="addmobile" /><br><br>

<label>Login Username</label>
<input type="text" value="<?php echo $_POST['addusername'];?>" name="addusername" /><br><br>
<label>Login Password</label>
<input type="text" value="<?php echo $_POST['addpassword'];?>" name="addpassword" /><br><br>
<label>Role</label>
<select name="addrole">
<?php while($rolemg = mysql_fetch_array($roles))
{
?>
<option value="<?php echo $rolemg['roleid'];?>"><?php echo $rolemg['rolename']; ?></option>
<?php }?>
</select>
<input type="submit" value="save" name="addform" />
</form>
<?php
if(isset($_POST['addform']))
{
$addempname = $_POST['addempname'];
$addfathername = $_POST['addfathername'];
$addmothername = $_POST['addmothername'];
$addaddress = $_POST['addaddress'];
$addpanno = $_POST['addpanno'];
$addemailid = $_POST['addemailid'];
$addmobile = $_POST['addmobile'];
$addusername = $_POST['addusername'];
$addpassword = $_POST['addpassword'];
$addrole = $_POST['addrole'];


$insert = "INSERT into adminform(addempname,addfathername,addmothername,addaddress,addpanno,addemailid,addmobile,addusername,addpassword) 
values('$addempname','$addfathername','$addmothername','$addaddress','$addpanno','$addemailid','$addmobile','$addusername','$addpassword')";
//print_r($insert);
$insertresult = mysql_query($insert);

$insertrole = "INSERT into userrole(adminid,roleid) values(LAST_INSERT_ID(),'$addrole')";
$insertroleresult = mysql_query($insertrole);
header("Location: user_list.php");
}
}
else
{
header("Location: login.php");
}
?>